﻿/*!	@file	r_gui_window_debuginfo.h
	@brief	Window_GUI
Copyright (c) 2010 Yuya Yamaguchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "r_gui_window_debuginfo.h"
#include "r_gui_server.h"
#include "r_gui_draw.h"
#include "r_gui_event.h"

#include "r_gui_widget_fps.h"
#include "r_gui_widget_profile_h.h"

#include "../thread/r_thread_profile_server.h"
#include "../window/r_window_systeminfo.h"
#include "../timer/r_timer_system.h"
#include "../util/r_util_str.h"

// >>>>>>>>>> RTTI >>>>>>>>>>
#include "../rtti/r_rtti_reflection_implement.h"
namespace r{
	namespace gui{
RRTTI_REFLECTION_IMPLEMENT ( r::gui::WindowDebugInfo, r::gui::Widget )
// <<<<<<<<<< RTTI <<<<<<<<<<


		WindowDebugInfo :: WindowDebugInfo()
			:
			hoverClose ( false )
		{
			cRWindowSystemInfo		wininfo;
			r_si32		tmpW;
			r_si32		tmpH;
			wininfo.getWindwowSize ( tmpW, tmpH );
			minWidth	= 200;
			minHeight	= 200;

			posX		= 0;
			posY		= 0;
			posW		= 200;
			posH		= tmpH;
			posOffR		= posOffL			= 4;
			posOffT		= posOffB			= 4;

			WidgetFPS*		guiFPS		= new WidgetFPS;
			addChild ( guiFPS );
			WidgetProfile*	guiProfile	= new WidgetProfileH;
			addChild ( guiProfile );
		}

		WindowDebugInfo :: ~WindowDebugInfo()
		{
		}

		typeConnection	WindowDebugInfo :: connectSlot ( const typeSignals<void() >::slot_type &slot )
		{
			return signalClose.connect ( slot );
		}

		void	WindowDebugInfo :: onUpdate ( Event& guiEvent )
		{
		}

		void	WindowDebugInfo :: onDraw ( draw::Draw& guidraw )
		{
			Server::instance		gui;
			const DrawInfo&		guiinfo = gui->getDrawInfo();
			// 自分の領域にあわせて描画領域を作成
			guidraw.setZ ( guidraw.getZ() + 1 );
			guidraw.setRect ( wposX, wposY, posW, posH );
		}

		void	WindowDebugInfo :: onClickInRectLMB ( Event& guiEvent )
		{
		#if 0
			// closeボタン
			if (
				( ( tx >= ( posW - s_rGUIWidgetWindowCloseOffsetX - s_rGUIWidgetWindowCloseW ) ) )
				&& ( ( tx <= ( posW - s_rGUIWidgetWindowCloseOffsetX ) ) )
				&& ( ty >= s_rGUIWidgetWindowCloseOffsetY )
				&& ( ty <= s_rGUIWidgetWindowCloseOffsetY + s_rGUIWidgetWindowCloseH )
			) {
				hoverClose		= true;
			}
		#endif // 0
		}

		void	WindowDebugInfo :: onDoubleClickInRectLMB ( Event& guiEvent )
		{
		}

		void	WindowDebugInfo :: onReleaseInRectLMB ( Event& guiEvent )
		{
			r_si32	x;
			r_si32	y;
			guiEvent.getCurPos ( x, y );
			r_si32	tx	=	x - wposX;
			r_si32	ty	=	y - wposY;
		#if 0
			// closeボタン
			if (
				( ( tx >= ( posW - s_rGUIWidgetWindowCloseOffsetX - s_rGUIWidgetWindowCloseW ) ) )
				&& ( ( tx <= ( posW - s_rGUIWidgetWindowCloseOffsetX ) ) )
				&& ( ty >= s_rGUIWidgetWindowCloseOffsetY )
				&& ( ty <= s_rGUIWidgetWindowCloseOffsetY + s_rGUIWidgetWindowCloseH )
			) {
				doClose();
			}
			hoverClose	= false;
		#endif // 0
		}

		void	WindowDebugInfo :: onReleaseOutRectLMB ( Event& guiEvent )
		{
			hoverClose	= false;
		}

		void	WindowDebugInfo :: onDragLMB ( Event& guiEvent )
		{
			if ( hoverClose == true ) {
				return;
			}
		}

		void	WindowDebugInfo :: onDragHoverInRectLMB ( Event& guiEvent )
		{
		}

		void	WindowDebugInfo :: onDragReleaseInRectLMB ( Event& guiEvent )
		{
		}

		void	WindowDebugInfo :: onHoverInRect ( Event& guiEvent )
		{
			r_si32	x;
			r_si32	y;
			guiEvent.getCurPos ( x, y );
			r_si32	tx	=	x - wposX;
			r_si32	ty	=	y - wposY;
		#if 0
			// closeボタン
			if (
				( ( tx >= ( posW - s_rGUIWidgetWindowCloseOffsetX - s_rGUIWidgetWindowCloseW ) ) )
				&& ( ( tx <= ( posW - s_rGUIWidgetWindowCloseOffsetX ) ) )
				&& ( ty >= s_rGUIWidgetWindowCloseOffsetY )
				&& ( ty <= s_rGUIWidgetWindowCloseOffsetY + s_rGUIWidgetWindowCloseH )
			) {
				hoverClose		= true;
			} else {
				hoverClose		= false;
			}
		#endif // 0
		}


		void	WindowDebugInfo :: doClose()
		{
			// クローズイベントをシグナルします
			signalClose();
			// 削除リストに登録します。
			Server::instance		guiserver;
			guiserver->remove ( this );
		}
	}
}

